#define _W5500_TASK_MODULE_

#include "osObjects.h"
#include "w5500task.h"
#include "pincfg.h"
#include "w5500_spi.h"
#include "w5500_hal.h"

void led_init(void);
void LedDutyCtr(void);

uint8_t W55Rd[128];
uint8_t CmdBack[4];
/*****************************************************************************//*!
*
* @brief   led task.
*     
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/
void W5500Task(void const *argument) {
    uint32_t Cnt;
    
    osDelay(300);
    
    SPI1_Init();
    W5500_Hal_Init();
    SPI1_CS = 1;
    
    W5500_RST = 0;
    osDelay(10);
    W5500_RST = 1;
    
    for (;;) {
        osDelay(10);
        
        SPI1_CS = 0;
        NOP30();
        CmdBack[0] = SPI1_ReadWriteByte(0);
        CmdBack[1] = SPI1_ReadWriteByte(0x5);
        CmdBack[2] = SPI1_ReadWriteByte(4);
        SPI1_ReadWriteByte(0x25);
        SPI1_ReadWriteByte(0x26);
        SPI1_ReadWriteByte(0x27);
        SPI1_ReadWriteByte(0x28);
        SPI1_CS = 1;
        
        NOP30();NOP30();
        NOP30();NOP30();
        
        SPI1_CS = 0;
        NOP30();
        CmdBack[0] = SPI1_ReadWriteByte(0);
        CmdBack[1] = SPI1_ReadWriteByte(0x0);
        CmdBack[2] = SPI1_ReadWriteByte(0);
        
        for(Cnt=0;Cnt<0x40;Cnt++)
            W55Rd[Cnt] = SPI1_ReadWriteByte(0xFF);

        SPI1_CS = 1;
        
        
        
        
        Cnt = 64;
        while(Cnt--)
            W55Rd[Cnt] = 0;
    }
}
